package demo.selenium;

import org.openqa.selenium.By;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.firefox.internal.ProfilesIni;
import org.springframework.stereotype.Component;

import java.util.Iterator;
import java.util.Set;
import java.util.concurrent.TimeUnit;

@Component
public class SeleniumUntils {

    public void seleniumTest() throws InterruptedException {
        //必须要有chromedriver.exe文件，selenium默认不能启动chrome
        System.setProperty("webdriver.chrome.driver", "src\\main\\resources\\files\\chromedriver.exe");
        // 创建一个 Chrome 的浏览器实例
        WebDriver driver = new ChromeDriver();
        // 最大化浏览器
//        driver.manage().window().maximize();
        // 固定窗口大小
        driver.manage().window().setSize(new Dimension(800, 800));
        //设置全局的隐形等待
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        driver.get("http://www.baidu.com");
        driver.findElement(By.id("kw")).clear();
        driver.findElement(By.id("kw")).sendKeys("spring");
        driver.findElement(By.id("su")).click();
        Thread.sleep(5000);
        driver.close();
        driver.quit();
    }

    public WebDriver openUrlSelenium(String url){
        System.setProperty("webdriver.chrome.driver", "src\\main\\resources\\files\\chromedriver.exe");
        WebDriver driver = new ChromeDriver();
        driver.get(url);
        return driver;
    }

    public WebDriver getSelenium(){
        System.setProperty("webdriver.chrome.driver", "src\\main\\resources\\files\\chromedriver.exe");
        WebDriver driver = new ChromeDriver();
        return driver;
    }

}
